#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	int N;
	vector<vector<int> > triangle;
	cin >> N;
	for(int i=0;i<=N;++i)
	{
		triangle.push_back(vector<int>(N + 1, 0));		
	}
	for(int i=1;i<=N;++i)
	{
		for (int j = 1; j <= i; ++j)
			cin >> triangle[i][j];
	}
	for(int i=2;i<=N;++i)
	{
		for(int j=1;j<=i;++j)
		{
			triangle[i][j] += max(triangle[i - 1][j - 1], triangle[i - 1][j]);
		}
	}
	cout << *max_element(triangle[N].begin(), triangle[N].end())<<endl;
}